//实现字符串操作的函数，有strlen()
#include <assert.h>
#include <stdio.h>

//字符串长度
int myStrLen(const char *str)
{
    assert(str);
    int len = 0;
    while(*str != '\0')
    {
        str++;
        len++;
    }

    return len;
}

//字符串copy
char * myStrcpy(char *dest, char *src)
{
    assert(dest);
    assert(src);
    char *retDest = dest;
    while((*dest = *src) != '\0')
    {
        dest++;
        src++;
    }
    return retDest;
}

//strcmp
int myStrcmp(const char *str1, const char *str2)
{
    assert(str1);
    assert(str2);
    while(*str1 && *str2 &&(*str1 == *str2))
    {
        str1++;
        str2++;
    }

    return *str1 - *str2;
}

//strcat
char *myStrcat(char *dest,const char* src)
{
    char *retDest = dest;
    while(*dest != '\0')
        dest++;

    while(*src != '\0')
    {
        *dest++ = *src++;
    }
    *dest = '\0'; //末尾符号
    return retDest;
}

int main()
{
    char * str = "china";
    int len = myStrLen(str);
    printf("len = %d\n",len);

    char *str1 = "shenzhen";
    char str2[10];
    myStrcpy(str2,str1);
    printf("str2 = %s\n",str2);

    char *str3 = "abcd";
    char *str4 = "abdc";
    int ret = myStrcmp(str3,str4);
    if(ret > 0)
    {
        printf("str3 > str4\n");
    }
    else if(ret < 0)
    {
        printf("str3 < str4\n");
    }else
    {
        printf("str3 == str4\n");
    }

    char str5[100] = {'a','b'};
    char *str6 = "pony";
    myStrcat(str5,str6);
    printf("str5=%s\n",str5);

    return 0;
}


